<?php 

header("Content-type: text/html; charset=utf-8");
include "./tpl/edit.html";
$db = include './db.php';
if($_POST){
foreach ($db as $key => $value) {
		if($key==$_GET["id"]){
			// var_dump($value["name"]);
			$db[$key]["name"] = $_POST["name"];
			$db[$key]["content"] = $_POST["content"];
		}
	}
	// $varname = $_POST["name"];
	// $varcontent = $_POST["content"];
	// $index = $_GET["id"];
	// $db[$index]["name"] = $varname;
	// $db[$index]["content"] = $varcontent;
	$newDb = var_export($db,TRUE);

	$newDb = "<?php return $newDb ?>";

	file_put_contents('./db.php', $newDb);

	$message = "修改成功";

	include './tpl/success.html';


}else{
	// 非POST,跳转回首页
	// 引入错误页面
	$error = "你将修改".$_GET["id"]."号文件";
 	include './tpl/error.html';
}


 ?>